import Util from "../../utils/util";

const app = getApp()
Component({
  properties: {
    logoutEpDialog: {
      type: Boolean,
      value: false,
    },
    logoutEpDialog1: {
      type: Boolean,
      value: false,
    },
    logoutEpDialog2: {
      type: Boolean,
      value: false,
    },
    dialogContent: Object,
    joinData: {
      type: Object,
      value: [],
    }
  },
  data: {},
  attached: function () {
  },
  methods: {
    closeDialog(e) {
      this.setData({
        logoutEpDialog: false,
        logoutEpDialog1: false,
        logoutEpDialog2: false,
      })
    },

    cancel(e) {
      if (!Util.isEmpty(this.data.dialogContent) && this.data.dialogContent.cancelLink) {
        wx.navigateTo({
          url: this.data.dialogContent.cancelLink
        })
      }

      //Todo 回调
      this.triggerEvent("cancelTip", this.data.dialogContent || null)
    },

    logoutElectPoolConfirm(e) {
      const that = this,
        key = e.currentTarget.dataset.key;
      const current_join = this.data.joinData.items[key]

      if (Util.isEmpty(current_join)) {
        app.Tips({title: "数据错误,请稍后再试", hideMask: true});
        return;
      }
      let joinData = this.data.joinData
      Util.showModelTip("确定退出" + current_join.title + "互选池吗？", "", "确定")
        .then(res => {
          if (res.confirm) {
            wx.showLoading({title: "正在退出..."})
            logoutElectPool(current_join.id).then(res => {
              joinData.items.splice(key, 1)
              that.setData({joinData: joinData})
              app.Tips({title: '退出成功', hideMask: true})
            }).catch(errmsg => {
              wx.hideLoading()
              return app.Tips({title: errmsg})
            })
          }
        })
    },

    lougoutElectPool(e) {
      const that = this

      if (!Util.isEmpty(this.data.dialogContent.confirmReturn)) {
        this.triggerEvent("confirmTip", this.data.dialogContent || null)
        this.setData({
          logoutEpDialog: false,
          logoutEpDialog1: false
        })
        return
      }

      if (!Util.isEmpty(this.data.dialogContent) && this.data.dialogContent.confirmLink) {
        wx.navigateTo({
          url: this.data.dialogContent.confirmLink
        })
        return;
      }

    },

  }
});